package org.auto;

import org.test.GPSPoint;
import org.test.GPSUtils;

/**
 * 经纬度转坐标
 */
public class TransTest {

    public static void main(String[] args) {
        double R = GPSUtils.EARTH_RADIUS * 1000;
        // 经纬度转坐标
        double lng = 86.1189390301772 * Math.PI / 180;
        double lat = 44.2320981390298 * Math.PI / 180;
        double x = R * Math.cos(lat) * Math.cos(lng);
        double y = R * Math.cos(lat) * Math.sin(lng);
        System.out.println(x + ", " + y);

        GPSPoint point = GPSUtils.gps2xy(new GPSPoint(lng, lat));
        System.out.println(point);

        // 坐标转经纬度
        double x2 = 308.9812748411796 * 1000; //米
        double y2 = 4554.486145795364 * 1000; //米

        double lng2 = Math.atan2(y2, x2) * 180 / Math.PI;
        double lat2 = Math.asin(y2 / R) * 180 / Math.PI;
        System.out.println(lng2 + ", " + lat2);

        GPSPoint point2 = GPSUtils.xy2gps(new GPSPoint(x2, y2));
        System.out.println(point2);


    }
}
